<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .heart {
      width: 20px;
      height: 15px;
      position: absolute;
      transform: translate3d(15px, 0, 0);
    }

    .heart::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      width: 10px;
      height: 15px;
      border-radius: 5px 5px 0 0;
      background: red;
      transform: rotate(-45deg);
      transform-origin: left bottom;
    }
    .heart::after {
      content: "";
      position: absolute;
      bottom: 0;
      left: 0;
      width: 15px;
      height: 10px;
      border-radius: 0 5px 5px 0;
      background: red;
      transform: rotate(-45deg);
      transform-origin: left bottom;
    }
    
    .move {
      animation: move .5s;
    }
    @keyframes move {
      100% {
        transform: translate3d(15px, -20px, 0);
        opacity: 0;
      }
    }
  
  </style>
</head>
<body>
  <!-- <i class="heart"></i> -->
  <script>
    /* var heart = document.querySelector('.heart')
    document.onclick = function () {
      heart.classList.add('move')
    }

    heart.addEventListener('animationend', function () {
      this.parentNode.removeChild(this)
    }) */
    
    function random () {
      return Math.floor(Math.random() * 256)
    }

    document.onclick = function (e) {
      var x = e.clientX - 15
      var y = e.clientY - 15
      var heart = document.createElement('i')
      heart.classList.add('heart')
      heart.addEventListener('animationend', function () {
        this.parentNode.removeChild(this)
      })
      
      // var color = "rgb(" + random() + "," + random() + ", " + random() + ")"
      heart.style.top = y + 'px'
      heart.style.left = x + 'px'
      // heart.style.backgroundColor = color

      document.body.appendChild(heart)
      heart.classList.add('move')
    }
  </script>
</body>
</html>